`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date: 2023/04/06 17:39:57
// Design Name: 
// Module Name: fir_match_zc
// Project Name: 
// Target Devices: 
// Tool Versions: 
// Description: 
// 
// Dependencies: 
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
//////////////////////////////////////////////////////////////////////////////////


module fir_match_zc(
    input clk,
    input rst,
    input signed [11:0] data,
    output reg signed[28:0] result_fir
    );

reg signed[11:0] coef1=12'd2047   ;
reg signed[11:0] coef2=12'd2037   ;
reg signed[11:0] coef3=12'd1956   ;
reg signed[11:0] coef4=12'd1691   ;
reg signed[11:0] coef5=12'd1111   ;
reg signed[11:0] coef6=12'd153    ;
reg signed[11:0] coef7=-12'd1024  ;
reg signed[11:0] coef8=-12'd1924  ;
reg signed[11:0] coef9=-12'd1844  ;
reg signed[11:0] coef10=-12'd456  ;
reg signed[11:0] coef11=12'd1429  ;
reg signed[11:0] coef12=12'd1956  ;
reg signed[11:0] coef13=12'd153   ;
reg signed[11:0] coef14=-12'd1924 ;
reg signed[11:0] coef15=-12'd1023 ;
reg signed[11:0] coef16=12'd1691  ;
reg signed[11:0] coef17=12'd1111  ;
reg signed[11:0] coef18=-12'd1844 ;
reg signed[11:0] coef19=-12'd456  ;
reg signed[11:0] coef20=12'd2037  ;
reg signed[11:0] coef21=-12'd1024 ;
reg signed[11:0] coef22=-12'd1023 ;
reg signed[11:0] coef23=12'd2037  ;
reg signed[11:0] coef24=-12'd1501 ;
reg signed[11:0] coef25=12'd153   ;
reg signed[11:0] coef26=12'd1111  ;
reg signed[11:0] coef27=-12'd1844 ;
reg signed[11:0] coef28=12'd2047  ;
reg signed[11:0] coef29=-12'd1924 ;
reg signed[11:0] coef30=12'd1691  ;
reg signed[11:0] coef31=-12'd1501 ;
								 
reg signed[11:0] coef32=12'd1429  ;
reg signed[11:0] coef33=-12'd1501 ;
reg signed[11:0] coef34=12'd1691  ;
reg signed[11:0] coef35=-12'd1924 ;
reg signed[11:0] coef36=12'd2047  ;
reg signed[11:0] coef37=-12'd1844 ;
reg signed[11:0] coef38=12'd1111  ;
reg signed[11:0] coef39=12'd153   ;
reg signed[11:0] coef40=-12'd1501 ;
reg signed[11:0] coef41=12'd2037  ;
reg signed[11:0] coef42=-12'd1024 ;
reg signed[11:0] coef43=-12'd1023 ;
reg signed[11:0] coef44=12'd2037  ;
reg signed[11:0] coef45=-12'd456  ;
reg signed[11:0] coef46=-12'd1844 ;
reg signed[11:0] coef47=12'd1111  ;
reg signed[11:0] coef48=12'd1691  ;
reg signed[11:0] coef49=-12'd1023 ;
reg signed[11:0] coef50=-12'd1924 ;
reg signed[11:0] coef51=12'd153   ;
reg signed[11:0] coef52=12'd1956  ;
reg signed[11:0] coef53=12'd1429  ;
reg signed[11:0] coef54=-12'd456  ;
reg signed[11:0] coef55=-12'd1844 ;
reg signed[11:0] coef56=-12'd1924 ;
reg signed[11:0] coef57=-12'd1023 ;
reg signed[11:0] coef58=12'd153   ;
reg signed[11:0] coef59=12'd1111  ;
reg signed[11:0] coef60=12'd1691  ;
reg signed[11:0] coef61=12'd1956  ;
reg signed[11:0] coef62=12'd2037  ;
reg signed[11:0] coef63=12'd2047  ;


reg signed [11:0] delay_pipeline[62:0];
//移位
always@(posedge clk)begin
	if(rst)begin
		delay_pipeline[0]<=12'd0;	
		delay_pipeline[1]<=12'd0;	
		delay_pipeline[2]<=12'd0;
		delay_pipeline[3]<=12'd0;
		delay_pipeline[4]<=12'd0;
		delay_pipeline[5]<=12'd0;
		delay_pipeline[6]<=12'd0;
		delay_pipeline[7]<=12'd0;
		delay_pipeline[8]<=12'd0;
		delay_pipeline[9]<=12'd0;
		delay_pipeline[10]<=12'd0;
		delay_pipeline[11]<=12'd0;
		delay_pipeline[12]<=12'd0;
		delay_pipeline[13]<=12'd0;
		delay_pipeline[14]<=12'd0;
		delay_pipeline[15]<=12'd0;
		delay_pipeline[16]<=12'd0;
		delay_pipeline[17]<=12'd0;
		delay_pipeline[18]<=12'd0;
		delay_pipeline[19]<=12'd0;
		delay_pipeline[20]<=12'd0;
		delay_pipeline[21]<=12'd0;
		delay_pipeline[22]<=12'd0;
		delay_pipeline[23]<=12'd0;
		delay_pipeline[24]<=12'd0;
		delay_pipeline[25]<=12'd0;
		delay_pipeline[26]<=12'd0;
		delay_pipeline[27]<=12'd0;
		delay_pipeline[28]<=12'd0;
		delay_pipeline[29]<=12'd0;
		delay_pipeline[30]<=12'd0;
		delay_pipeline[31]<=12'd0;
						
		delay_pipeline[32]<=12'd0;
		delay_pipeline[33]<=12'd0;
		delay_pipeline[34]<=12'd0;
		delay_pipeline[35]<=12'd0;
		delay_pipeline[36]<=12'd0;
		delay_pipeline[37]<=12'd0;
		delay_pipeline[38]<=12'd0;
		delay_pipeline[39]<=12'd0;
		delay_pipeline[40]<=12'd0;
		delay_pipeline[41]<=12'd0;
		delay_pipeline[42]<=12'd0;
		delay_pipeline[43]<=12'd0;
		delay_pipeline[44]<=12'd0;
		delay_pipeline[45]<=12'd0;
		delay_pipeline[46]<=12'd0;
		delay_pipeline[47]<=12'd0;
	    delay_pipeline[48]<=12'd0;
        delay_pipeline[49]<=12'd0;
        delay_pipeline[50]<=12'd0;
        delay_pipeline[51]<=12'd0;
        delay_pipeline[52]<=12'd0;
        delay_pipeline[53]<=12'd0;
        delay_pipeline[54]<=12'd0;
        delay_pipeline[55]<=12'd0;
        delay_pipeline[56]<=12'd0;
        delay_pipeline[57]<=12'd0;
        delay_pipeline[58]<=12'd0;
        delay_pipeline[59]<=12'd0;
        delay_pipeline[60]<=12'd0;
        delay_pipeline[61]<=12'd0;
        delay_pipeline[62]<=12'd0;
		
	end
	else begin
		delay_pipeline[0] <=data;
		delay_pipeline[1] <=delay_pipeline[0];
		delay_pipeline[2] <=delay_pipeline[1];
		delay_pipeline[3] <=delay_pipeline[2];
		delay_pipeline[4] <=delay_pipeline[3];
		delay_pipeline[5] <=delay_pipeline[4];
		delay_pipeline[6] <=delay_pipeline[5];
		delay_pipeline[7] <=delay_pipeline[6];
		delay_pipeline[8] <=delay_pipeline[7];
		delay_pipeline[9] <=delay_pipeline[8];
		delay_pipeline[10]<=delay_pipeline[9];
		delay_pipeline[11]<=delay_pipeline[10];
		delay_pipeline[12]<=delay_pipeline[11];
		delay_pipeline[13]<=delay_pipeline[12];
		delay_pipeline[14]<=delay_pipeline[13];
		delay_pipeline[15]<=delay_pipeline[14];
		delay_pipeline[16]<=delay_pipeline[15];
		delay_pipeline[17]<=delay_pipeline[16];
		delay_pipeline[18]<=delay_pipeline[17];
		delay_pipeline[19]<=delay_pipeline[18];
		delay_pipeline[20]<=delay_pipeline[19];
		delay_pipeline[21]<=delay_pipeline[20];
		delay_pipeline[22]<=delay_pipeline[21];
		delay_pipeline[23]<=delay_pipeline[22];
		delay_pipeline[24]<=delay_pipeline[23];
		delay_pipeline[25]<=delay_pipeline[24];
		delay_pipeline[26]<=delay_pipeline[25];
		delay_pipeline[27]<=delay_pipeline[26];
		delay_pipeline[28]<=delay_pipeline[27];
		delay_pipeline[29]<=delay_pipeline[28];
		delay_pipeline[30]<=delay_pipeline[29];
		delay_pipeline[31]<=delay_pipeline[30];
					 
		delay_pipeline[32]<=delay_pipeline[31];
		delay_pipeline[33]<=delay_pipeline[32];
		delay_pipeline[34]<=delay_pipeline[33];
		delay_pipeline[35]<=delay_pipeline[34];
		delay_pipeline[36]<=delay_pipeline[35];
		delay_pipeline[37]<=delay_pipeline[36];
		delay_pipeline[38]<=delay_pipeline[37];
		delay_pipeline[39]<=delay_pipeline[38];
		delay_pipeline[40]<=delay_pipeline[39];
		delay_pipeline[41]<=delay_pipeline[40];
		delay_pipeline[42]<=delay_pipeline[41];
		delay_pipeline[43]<=delay_pipeline[42];
		delay_pipeline[44]<=delay_pipeline[43];
		delay_pipeline[45]<=delay_pipeline[44];
		delay_pipeline[46]<=delay_pipeline[45];
		delay_pipeline[47]<=delay_pipeline[46];
		delay_pipeline[48]<=delay_pipeline[47];
		delay_pipeline[49]<=delay_pipeline[48];
		delay_pipeline[50]<=delay_pipeline[49];
		delay_pipeline[51]<=delay_pipeline[50];
		delay_pipeline[52]<=delay_pipeline[51];
		delay_pipeline[53]<=delay_pipeline[52];
		delay_pipeline[54]<=delay_pipeline[53];
		delay_pipeline[55]<=delay_pipeline[54];
		delay_pipeline[56]<=delay_pipeline[55];
		delay_pipeline[57]<=delay_pipeline[56];
		delay_pipeline[58]<=delay_pipeline[57];
	    delay_pipeline[59]<=delay_pipeline[58];
        delay_pipeline[60]<=delay_pipeline[59];
        delay_pipeline[61]<=delay_pipeline[60];
        delay_pipeline[62]<=delay_pipeline[61];
	end
end

reg signed[23:0] mult[62:0];


always@(posedge clk)begin
	if(rst)begin
		mult[0]<=24'd0;
	    mult[1]<=24'd0;
	    mult[2]<=24'd0;
	    mult[3]<=24'd0;
	    mult[4]<=24'd0;
	    mult[5]<=24'd0;
	    mult[6]<=24'd0;
	    mult[7]<=24'd0;
	    mult[8]<=24'd0;
	    mult[9]<=24'd0;
	    mult[10]<=24'd0;
	    mult[11]<=24'd0;
	    mult[12]<=24'd0;
	    mult[13]<=24'd0;
	    mult[14]<=24'd0;
	    mult[15]<=24'd0;
	    mult[16]<=24'd0;
	    mult[17]<=24'd0;
	    mult[18]<=24'd0;
	    mult[19]<=24'd0;
	    mult[20]<=24'd0;
	    mult[21]<=24'd0;
	    mult[22]<=24'd0;
	    mult[23]<=24'd0;
	    mult[24]<=24'd0;
	    mult[25]<=24'd0;
	    mult[26]<=24'd0;
	    mult[27]<=24'd0;
	    mult[28]<=24'd0;
	    mult[29]<=24'd0;
	    mult[30]<=24'd0;
	    mult[31]<=24'd0;
	    				
	    mult[32]<=24'd0;
	    mult[33]<=24'd0;
	    mult[34]<=24'd0;
	    mult[35]<=24'd0;
	    mult[36]<=24'd0;
	    mult[37]<=24'd0;
	    mult[38]<=24'd0;
	    mult[39]<=24'd0;
	    mult[40]<=24'd0;
	    mult[41]<=24'd0;
	    mult[42]<=24'd0;
	    mult[43]<=24'd0;
	    mult[44]<=24'd0;
	    mult[45]<=24'd0;
	    mult[46]<=24'd0;
	    mult[47]<=24'd0;
	    mult[48]<=24'd0;
	    mult[49]<=24'd0;
	    mult[50]<=24'd0;
	    mult[51]<=24'd0;
	    mult[52]<=24'd0;
	    mult[53]<=24'd0;
	    mult[54]<=24'd0;
	    mult[55]<=24'd0;
	    mult[56]<=24'd0;
	    mult[57]<=24'd0;
	    mult[58]<=24'd0;
	    mult[59]<=24'd0;
	    mult[60]<=24'd0;
	    mult[61]<=24'd0;
	    mult[62]<=24'd0;
	end
	else begin
		mult[0] <=delay_pipeline[0] *coef1 ;
		mult[1] <=delay_pipeline[1] *coef2 ;
		mult[2] <=delay_pipeline[2] *coef3 ;
		mult[3] <=delay_pipeline[3] *coef4 ;
		mult[4] <=delay_pipeline[4] *coef5 ;
		mult[5] <=delay_pipeline[5] *coef6 ;
		mult[6] <=delay_pipeline[6] *coef7 ;
		mult[7] <=delay_pipeline[7] *coef8 ;
		mult[8] <=delay_pipeline[8] *coef9 ;
		mult[9] <=delay_pipeline[9] *coef10;
		mult[10]<=delay_pipeline[10]*coef11;
		mult[11]<=delay_pipeline[11]*coef12;
		mult[12]<=delay_pipeline[12]*coef13;
		mult[13]<=delay_pipeline[13]*coef14;
		mult[14]<=delay_pipeline[14]*coef15;
		mult[15]<=delay_pipeline[15]*coef16;
		mult[16]<=delay_pipeline[16]*coef17;
		mult[17]<=delay_pipeline[17]*coef18;
		mult[18]<=delay_pipeline[18]*coef19;
		mult[19]<=delay_pipeline[19]*coef20;
		mult[20]<=delay_pipeline[20]*coef21;
		mult[21]<=delay_pipeline[21]*coef22;
		mult[22]<=delay_pipeline[22]*coef23;
		mult[23]<=delay_pipeline[23]*coef24;
		mult[24]<=delay_pipeline[24]*coef25;
		mult[25]<=delay_pipeline[25]*coef26;
		mult[26]<=delay_pipeline[26]*coef27;
		mult[27]<=delay_pipeline[27]*coef28;
		mult[28]<=delay_pipeline[28]*coef29;
		mult[29]<=delay_pipeline[29]*coef30;
		mult[30]<=delay_pipeline[30]*coef31;
		mult[31]<=delay_pipeline[31]*coef32;
									
		mult[32]<=delay_pipeline[32]*coef33;
		mult[33]<=delay_pipeline[33]*coef34;
		mult[34]<=delay_pipeline[34]*coef35;
		mult[35]<=delay_pipeline[35]*coef36;
		mult[36]<=delay_pipeline[36]*coef37;
		mult[37]<=delay_pipeline[37]*coef38;
		mult[38]<=delay_pipeline[38]*coef39;
		mult[39]<=delay_pipeline[39]*coef40;
		mult[40]<=delay_pipeline[40]*coef41;
		mult[41]<=delay_pipeline[41]*coef42;
		mult[42]<=delay_pipeline[42]*coef43;
		mult[43]<=delay_pipeline[43]*coef44;
		mult[44]<=delay_pipeline[44]*coef45;
		mult[45]<=delay_pipeline[45]*coef46;
		mult[46]<=delay_pipeline[46]*coef47;
		mult[47]<=delay_pipeline[47]*coef48;
		mult[48]<=delay_pipeline[48]*coef49;
		mult[49]<=delay_pipeline[49]*coef50;
		mult[50]<=delay_pipeline[50]*coef51;
		mult[51]<=delay_pipeline[51]*coef52;
		mult[52]<=delay_pipeline[52]*coef53;
		mult[53]<=delay_pipeline[53]*coef54;
		mult[54]<=delay_pipeline[54]*coef55;
		mult[55]<=delay_pipeline[55]*coef56;
		mult[56]<=delay_pipeline[56]*coef57;
		mult[57]<=delay_pipeline[57]*coef58;
		mult[58]<=delay_pipeline[58]*coef59;
		mult[59]<=delay_pipeline[59]*coef60;
		mult[60]<=delay_pipeline[60]*coef61;
		mult[61]<=delay_pipeline[61]*coef62;
		mult[62]<=delay_pipeline[62]*coef63;		
	end
end

always@(posedge clk)begin
	if(rst)begin
		result_fir<=29'd0;
	end
	else begin
		result_fir<=mult[0]+mult[1]+mult[2]+mult[3]+mult[4]+mult[5]+mult[6]
					+mult[7]+mult[8]+mult[9]+mult[10]+mult[10]+mult[12]+mult[13]
					+mult[14]+mult[15]+mult[16]+mult[17]+mult[18]+mult[19]+mult[20]
					+mult[21]+mult[22]+mult[23]+mult[24]+mult[25]+mult[26]+mult[27]
					+mult[28]+mult[29]+mult[30]+mult[31]+mult[32]+mult[33]+mult[34]
					+mult[35]+mult[36]+mult[37]+mult[38]+mult[39]+mult[40]+mult[41]
					+mult[42]+mult[43]+mult[44]+mult[45]+mult[46]+mult[47]+mult[48]
					+mult[49]+mult[50]+mult[51]+mult[52]+mult[53]+mult[54]+mult[55]
					+mult[56]+mult[57]+mult[58]+mult[59]+mult[60]+mult[61]+mult[62];
	end
end

endmodule
